<!--
描述：新增留言
开发人：yyp
开发日期：2019/10/24
-->
<template lang="pug">
  keep-alive
    kalix-table(bizKey="Message" title='留言表' ref="kalixTable"
    v-bind:tableFields="tableFields"
    v-bind:targetURL="MessageURL"
    v-bind:bizDialog="MessageDialog"
    v-bind:btnList="MessageBtnList"
    v-bind:customTableTool="customTableTool"
    v-bind:buttonPermissionPrefix="buttonPermissionPrefix"
    v-bind:toolbarBtnList="toolbarBtnList"
    bizSearch="messageSearch")
      template(slot="tableColumnSlot")
        el-table-column(prop="userName" label="用户名称" align="center")
        el-table-column(prop="messageTitle" label="评论标题" align="center")
        el-table-column(prop="messageContent" label="评论内容" align="center")
        el-table-column(prop="messageDateTime" label="评论时间" align="center")
          template(slot-scope="scope")
            span {{dataFormat(scope.row.messageDateTime)}}
        el-table-column(prop="messageFlag" label="是否置顶" align="center")
          template(slot-scope="scope")
            span {{scope.row.messageFlag === true ? '是' : '否'}}
        el-table-column(prop="messageJingFlag" label="是否精品" align="center")
          template(slot-scope="scope")
            span {{scope.row.messageJingFlag === true ? '是' : '否'}}
</template>

<script type="text/ecmascript-6">
  import {MessageURL, MessageBtnPermissionPrefix} from '../../config.toml'
  import {MessageConfigBtnList} from './config'
  import KalixTable from '../../../../../components/corelib/components/common/baseTable'
  import {ON_REFRESH_DATA} from '../../../../../components/corelib/components/common/event.toml'

  export default {
    name: 'kalix-mplive-message',
    components: {KalixTable},
    data() {
      return {
        MessageURL: MessageURL,
        tableFields: [
          {prop: 'userName', label: '用户名称'},
          {prop: 'messageDateTime', label: '时间'},
          {prop: 'messageTitle', label: '评论标题'},
          {prop: 'messageContent', label: '评论内容'},
          {prop: 'messageFlag', label: '是否置顶'},
          {prop: 'messageJingFlag', label: '是否精品'}
        ],
        MessageDialog: [
          {id: 'add', dialog: 'messageAdd'},
          {id: 'edit', dialog: 'messageEdit'},
          {id: 'view', dialog: 'messageView'}
        ],
        MessageBtnList: MessageConfigBtnList,
        toolbarBtnList: [
          {id: 'add', isShow: false, title: '添加', icon: 'icon-pinleizengjia', isPermission: true}
        ],
        buttonPermissionPrefix: MessageBtnPermissionPrefix
      }
    },
    methods: {
      customTableTool(row, btnId, that) {
        switch (btnId) {
          case 'zhiding': { // 启用/停用
            let warnInfo = '确定要' + (row.messageFlag === false ? '置顶' : '取消置顶') + '吗？'
            that.$confirm(warnInfo, '警告', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              let messageF = false
              if (row.messageFlag === false) {
                messageF = true
              }
              return this.$http.request({
                method: 'PUT',
                url: MessageURL + '/' + row.id,
                params: {},
                data: {
                  id: row.id,
                  messageFlag: messageF,
                  messageJingFlag: row.messageJingFlag,
                  uid: row.uid
                }
              })
            }).then((res) => {
              console.log(res)
              this.$KalixMessage.processResult(res)
              this.$KalixEventBus.$emit(ON_REFRESH_DATA)
            })
            break
          }
          case 'jing': { // 启用/停用
            let warnInfo = '确定要' + (row.messageJingFlag === false ? '精品' : '取消精品') + '吗？'
            that.$confirm(warnInfo, '警告', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              let jingmessageF = false
              if (row.messageJingFlag === false) {
                jingmessageF = true
              }
              return this.$http.request({
                method: 'PUT',
                url: MessageURL + '/' + row.id,
                params: {},
                data: {
                  id: row.id,
                  messageFlag: row.messageFlag,
                  messageJingFlag: jingmessageF,
                  uid: row.uid
                }
              })
            }).then((res1) => {
              console.log(res1)
              this.$KalixMessage.processResult(res1)
              this.$KalixEventBus.$emit(ON_REFRESH_DATA)
            })
            break
          }
        }
      },
      dataFormat(val) {
        let d = new Date(val)
        return this.$M_FormatDate(d, 'yyyy-MM-dd hh:mm:ss')
      }
    }
  }
</script>

<style scoped lang="stylus">

</style>
